/**
* @description: 769. 最多能完成排序的块
* @author hewei
* @date 2022/8/13 15:47
* @version 1.0
*/

public class MaxChunksToSorted {

    public int maxChunksToSorted(int[] arr) {
        int n = arr.length;
        int i = 0;
        int ans = 0;
        while (i < n) {
            int index = arr[i];
            ++i;
            while (i <= index) {
                if (arr[i] > index) index = arr[i];
                ++i;
            }
            ans++;
        }
        return ans;
    }
}
